#测试画眉AI人脸合成

import requests
from common.logger import Log

log = Log()

def get_face(categoryId):
    url = "http://micro.brium.cn/qknode-hm/face/getWallpaperInfoPageList"
    params = {"categoryId7caaf":categoryId,
              "online":"up",
                "pageNo":1,
              "pageSize":10}
    r = requests.get(url=url,params=params)
    pic = r.json()["data"]["list"]
    pic_list =[]
    for i in pic:
        if i["formateUrl"]:
            pic_list.append(i["formateUrl"])
        else:
            pic_list.append(i["url"])
    return pic_list

def face_ai(pic_list):
    pic = "https://static1.qknode.com/rest/img/86/5321360151074269086.jpg"
    url = "http://micro.brium.cn/qknode-hm/face/getFaceMerge"
    for i in pic_list:
        params ={"alpha":"0.25","imageTemplate":i,"imageTarget":pic}
        r = requests.session().get(url=url,params=params).json()
        assert r["code"] != 1001,log.error(f"图片合成失败：{i}")

if __name__ == "__main__":
    #get_face("f0dfc3fb6a9247edbd8455da58549ddf")

    face_ai(get_face("f0dfc3fb6a9247edbd8455da58549ddf"))
    face_ai(get_face("e3a10c1f41914c97add72f882ce61ee7"))
    face_ai(get_face("7caaf22cc75d4e9190a0382d7617661f"))
    face_ai(get_face("62ce7dda2d8b429d888380045c4d9d84"))
    

